﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace fsw_backup
{
    class EventItem
    {
        private const int _logDelay = 1;
        private const int _bakDelay = 3;

        public string FullPath { get; private set; }
        public DateTime LastEvent { get; private set; }
        public DateTime NextEventLog { get; private set; }

        public bool ReadyToLog { get { return _eventCount > 0 && NextEventLog < DateTime.Now; } }
        public bool ReadyToBackup { get { return LastEvent.AddSeconds(_bakDelay) < DateTime.Now; } }

        private int _eventCount;

        public EventItem(string FullPath)
        {
            this.FullPath = FullPath;
            SetNextEventLog();
            AddEvent();
        }

        public void AddEvent()
        {
            LastEvent = DateTime.Now;
            _eventCount++;
        }

        public void SetNextEventLog()
        {
            NextEventLog = DateTime.Now.AddSeconds(_logDelay);
            _eventCount = 0;
        }

        public override string ToString()
        {
            string format = "{0} {1}({2})";
            return string.Format(format, System.IO.Path.GetFileName(FullPath), LastEvent, NextEventLog);
        }
    }
}
